<template>


  <div>
    <div class="row-header">
      <el-form :inline="true" label-width="50px">
        <el-form-item label=" ">
          <el-date-picker
            class="select"
            v-model="insertTime"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至" start-placeholder="交易开始日期" end-placeholder="交易结束日期"
            size="small" style="width: 100%"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item label=" " >
          <el-select v-model="dictTransactionTypeSearch" placeholder="请选择交易类型" style="width: 100%;" size="small">
            <el-option v-for="dictTransactionType in dictTransactionTypeSelect" :key="dictTransactionType.value"
                       :label="dictTransactionType.label" :value="dictTransactionType.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" " >
          <el-select v-model="dictMethodSearch" placeholder="请选择交易方式" style="width: 100%;" size="small">
            <el-option v-for="dictMethod in dictMethodSelect" :key="dictMethod.value" :label="dictMethod.label"
                       :value="dictMethod.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="row-form-btn">
        <el-button type="shenda" size="small" @click="currentPage = 1 ; initData()">查询</el-button>
      </div>
    </div>
    <div class="split-line"></div>
    <div class="row-main">
      <el-button type="shenda" size="small" icon="el-icon-back" @click="toBack">返回</el-button>
      <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableDataForRecord" tooltip-effect="dark"
                class="row-main-table" @selection-change="handleSelectionChange" v-loading.fullscreen=""
                element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.2)">
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column prop="loginName" label="客户账号" align="center"></el-table-column>
        <el-table-column prop="insertTimeDate" label="交易时间" align="center"></el-table-column>
        <el-table-column prop="dictTransactionTypeName" label="交易类型" align="center"></el-table-column>
        <el-table-column prop="dictMethodName" label="交易方式" align="center"></el-table-column>
        <el-table-column prop="beforBalance" label="交易前费用" align="center"></el-table-column>
        <el-table-column prop="transactionMoney" label="交易费用" align="center"></el-table-column>
        <el-table-column prop="afterBalance" label="交易后余额" align="center"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center"></el-table-column>
        <el-table-column prop="insertUserName" label="交易操作人" align="center"></el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" class="row-main-pager"
                     :current-page.sync="currentPage" :page-size="pageSize" layout="total,sizes,prev, pager, next, jumper"
                     :page-sizes="[10,20,50,100]" :total="total" background></el-pagination>

    </div>
  </div>
</template>

<script>
import {getRecord} from '@/api/getData'

export default {
  name: 'Record',
  data() {
    return {
      dictMethodSearch: "",
      dictMethodSelect: [{
        value: '',
        label: '请选择交易方式'
      }, {
        value: 'WX',
        label: '微信'
      }, {
        value: 'ZFB',
        label: '支付宝'
      }, {
        value: 'XJ',
        label: '银行卡'
      }],
      dictTransactionTypeSearch: "",
      dictTransactionTypeSelect: [{
        value: '',
        label: '请选择交易类型'
      }, {
        value: 'RETURNMONEY',
        label: '返佣提现'
      }, {
        value: 'RECHARGE',
        label: '充值'
      }, {
        value: 'autoreturn',
        label: '自动提现'
      }],
      insertTime: "",
      agentName: "",
      agentId: "",
      pageSize: 10,
      total: 0,
      currentPage: 1,
      maxPage: 1,
      form: {
        date1: '',
        date2: ''
      },
      tableDataForRecord: [],
      ascs: [],
      descs: ['insertTime']
    }

  },
  created() {
    this.loginName = this.$route.params.agentName;
    this.agentId = this.$route.params.id;
    this.initData()
  },
  methods: {

    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`)
      this.pageSize = val;
      this.currentPage = 1;
      this.initData()
    },
    handleCurrentChange(val) {
      //console.log(`当前页: ${val}`)
      this.currentPage = val
      this.initData()
    },
    toBack() {
      this.$router.push({path: '/user/index'})
    },

    // 页面初始化
    async initData(theKey) {
      let startTime = null
      let endTime = null
      if (this.insertTime != "" && this.insertTime != null) {
        startTime = this.insertTime[0]
        endTime = this.insertTime[1]
      }

      const returnData = await getRecord({
        userId: this.agentId,
        dictMethod: this.dictMethodSearch,
        dictTransactionType: this.dictTransactionTypeSearch,
        startDate: startTime,
        endDate: endTime,
        page: {
          current: this.currentPage + '',
          size: this.pageSize + '',
          ascs: this.ascs,
          descs: this.descs
        }
      }, {
        obj: this,
        key: 'tableLoading;' + theKey
      })
      this.tableDataForRecord = [];
      this.total = 0;
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        // 数据回显
        returnData.data.records.map(item => {
          const obj = {}
          obj.loginName = this.loginName // 代理名称
          obj.insertTimeDate = item.insertTimeDate // 交易时间
          obj.dictTransactionTypeName = item.dictTransactionTypeName // 交易类型
          obj.dictMethodName = item.dictMethodName // 交易方式
          obj.beforBalance = item.beforBalance // 交易前费用
          obj.transactionMoney = item.transactionMoney // 交易费用
          obj.afterBalance = item.afterBalance // 交易后余额
          obj.remark = item.remark // 备注
          obj.insertUserName = item.insertUserName // 交易操作人
          this.tableDataForRecord.push(obj)
        })
        this.total = returnData.data.total
        this.tableLoading = false
      }
    }

  }
}
</script>

<style scoped lang="scss">

.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -39px;

  button {
    display: block;
  }

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}
</style>
